﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PressOB_Framework.ViewModel
{
    class MainWindowModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private bool isRun;
        private bool isPause;
        private string path;
        private string[] ports;
        private string com;
        private string[] freSelect;
        private string frequency;
        private string timesPs;
        public MainWindowModel()
        {
            freSelect = new string[] { "9600", "19200" ,"38400","57600","115200"};
            Frequency = Properties.Settings.Default.frequency;
            Path = Properties.Settings.Default.path;
            TimesPs = Properties.Settings.Default.timesPs;
            if (path == "")
            {
                path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }
        }
        public bool IsRun
        {
            get { return isRun; }
            set
            {
                if(isRun != value)
                {
                    isRun = value;
                    OnPropertyChanged(nameof(isRun));
                    OnPropertyChanged("NotRun");
                }
            }
        }
        public bool IsPause
        {
            get { return isPause; }
            set
            {
                if (isPause != value)
                {
                    isPause = value;
                    OnPropertyChanged(nameof(isPause));
                }
            }
        }

        public string Path { get => path; set
            {
                if (path != value)
                {
                    path = value;
                    OnPropertyChanged(nameof(path));
                }
            }
        }

        public string[] Ports { get => ports; set
            {
                ports = value;
                OnPropertyChanged(nameof(ports));
            }
        }

        public bool NotRun { get { return !isRun; } }

        public string Frequency
        {
            get => frequency; set
            {
                if (frequency != value)
                {
                    frequency = value;
                    OnPropertyChanged(nameof(frequency));
                }
            }
        }

        public string[] FreSelect
        {
            get => freSelect; set
            {
                if (freSelect != value)
                {
                    freSelect = value;
                    OnPropertyChanged(nameof(freSelect));
                }
            }
        }

        public string Com { get => com; set
            {
                if(com != value)
                {
                    com = value;
                    OnPropertyChanged(nameof(com));
                }
            }
        }

        public string TimesPs
        {
            get => timesPs; set
            {
                if(timesPs != value)
                {
                    timesPs = value;
                    OnPropertyChanged(nameof(timesPs));
                }
                
            }
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        // 保存本次选择
        public void SaveSetting()
        {
            Properties.Settings.Default.frequency = Frequency;
            Properties.Settings.Default.path = Path;
            Properties.Settings.Default.timesPs = TimesPs;
            Properties.Settings.Default.Save();
        }
    }
}
